package com.ttg.web.service.Impl;

import com.ttg.common.entities.BasePage;
import com.ttg.common.enums.ErrorCodeEnums;
import com.ttg.common.exception.BaseException;
import com.ttg.model.dto.IndustryPageDTO;
import com.ttg.model.dto.IndustrySelectDTO;
import com.ttg.model.pojo.IndustryInfo;
import com.ttg.model.vo.IndustryInfoVO;
import com.ttg.model.vo.IndustrySelectVO;
import com.ttg.model.vo.TagVo;
import com.ttg.web.dao.IndustryInfoDao;
import com.ttg.web.service.IndustryInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * Description：
 * Author: chenyou
 * Date: 2025/11/6 15:53
 * Company: ttg
 * Copyright: Copyright (c) 2025
 */
@Service
public class IndustryInfoServiceImpl implements IndustryInfoService {

    @Autowired
    private IndustryInfoDao industryInfoDao;

    @Override
    public List<IndustrySelectVO> firstLevelList() {
        List<IndustryInfo> list = industryInfoDao.fisrtLevelList();
        return list.stream().map(o ->{
            IndustrySelectVO vo = new IndustrySelectVO();
            vo.setIndClsId(o.getIndClsId1());
            vo.setIndClsName(o.getIndClsName1());
            return vo;
        }).collect(Collectors.toList());
    }

    @Override
    public List<IndustrySelectVO> twoLevelList(IndustrySelectDTO industrySelectDTO) {
        List<IndustryInfo> list = industryInfoDao.twoLevelList(industrySelectDTO.getClsId1());
        return list.stream().map(o ->{
            IndustrySelectVO vo = new IndustrySelectVO();
            vo.setIndClsId(o.getIndClsId2());
            vo.setIndClsName(o.getIndClsName2());
            return vo;
        }).collect(Collectors.toList());
    }

    @Override
    public BasePage<IndustryInfoVO> page(IndustryPageDTO reqDto) {
//        if (Objects.isNull(reqDto)){
//            throw new BaseException(ErrorCodeEnums.PARAM_IS_NULL);
//        }
        BasePage<IndustryInfoVO> tagVoBasePage = industryInfoDao.page(reqDto);
        return tagVoBasePage;
    }
}
